package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.Common;
import com.macro.mall.portal.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author super
 * @title: CommonController
 * @description: TODO
 * @date 2020/8/15 14:16
 */
@Slf4j
@RestController
@RequestMapping("common")
@Api(tags = "common", description = "字典表(common)")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @ApiOperation("查询字典表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult list(Common common) {
        List<Common> commons = commonService.find(common);
        return CommonResult.success(commons);
    }



    @ApiOperation("查询字典详情")
    @RequestMapping(value = "/findOne", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Common> getById(@ApiParam(value = "id") @RequestParam(value = "id", required = false) Integer id,
                                        @ApiParam(value = "commonType") @RequestParam(value = "commonType", required = false) String commonType) {
        try {
            Common one = commonService.findOne(id,commonType);
            return CommonResult.success(one);
        } catch (Exception e) {
           log.error("exception", e);
        }
        return CommonResult.failed();
    }



}
